/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.tb_goods_receipt_company.web;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.mysql.fabric.xmlrpc.base.Data;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.utils.ToolsUtil;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.tb_areas.service.TbAreasService;
import com.thinkgem.jeesite.modules.tb_goods_receipt_company.entity.TbGoodsReceiptCompany;
import com.thinkgem.jeesite.modules.tb_goods_receipt_company.service.TbGoodsReceiptCompanyService;

/**
 * 收货公司管理Controller
 * @author ZhangYangZe
 * @version 2017-05-14
 */
@Controller
@RequestMapping(value = "${adminPath}/tb_goods_receipt_company/tbGoodsReceiptCompany")
public class TbGoodsReceiptCompanyController extends BaseController {

	@Autowired
	private TbGoodsReceiptCompanyService tbGoodsReceiptCompanyService;
	@Autowired
	private TbAreasService tbAreasService;
	/**
	 * 获取单条数据
	 * @param String
	 * @return TbGoodsReceiptCompany
	 */
	@ModelAttribute
	public TbGoodsReceiptCompany get(@RequestParam(required=false) String id) {
		TbGoodsReceiptCompany entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tbGoodsReceiptCompanyService.get(id);
		}
		if (entity == null){
			entity = new TbGoodsReceiptCompany();
		}
		return entity;
	}
	/**
	 * 获取查询分页数据
	 * @param TbGoodsReceiptCompany
	 * @param HttpServletRequest
	 * @param HttpServletResponse
	 * @param Model
	 * @return String
	 */
	@RequiresPermissions("tb_goods_receipt_company:tbGoodsReceiptCompany:view")
	@RequestMapping(value = {"list", ""})
	public String list(TbGoodsReceiptCompany tbGoodsReceiptCompany, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TbGoodsReceiptCompany> page = tbGoodsReceiptCompanyService.findPage(new Page<TbGoodsReceiptCompany>(request, response), tbGoodsReceiptCompany); 
		model.addAttribute("page", page);
		return "modules/tb_goods_receipt_company/tbGoodsReceiptCompanyList";
	}
	/**
	 * 查询下级城市（联动菜单用）
	 * @param TbGoodsReceiptCompany
	 * @param Model
	 * @return String
	 */
	@RequiresPermissions("tb_goods_receipt_company:tbGoodsReceiptCompany:view")
	@RequestMapping(value = "form")
	public String form(TbGoodsReceiptCompany tbGoodsReceiptCompany, Model model) {
		model.addAttribute("tbAreas", tbAreasService.findCityByParentId("0"));
		model.addAttribute("tbGoodsReceiptCompany", tbGoodsReceiptCompany);
		return "modules/tb_goods_receipt_company/tbGoodsReceiptCompanyForm";
	}
	/**
	 * 保存数据（插入或更新）
	 * @param TbGoodsReceiptCompany
	 * @param Model
	 * @return String
	 */
	@RequiresPermissions("tb_goods_receipt_company:tbGoodsReceiptCompany:edit")
	@RequestMapping(value = "save")
	public String save(TbGoodsReceiptCompany tbGoodsReceiptCompany, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tbGoodsReceiptCompany)){
			return form(tbGoodsReceiptCompany, model);
		}
		tbGoodsReceiptCompanyService.save(tbGoodsReceiptCompany);
		addMessage(redirectAttributes, "保存收货公司成功");
		return "redirect:"+Global.getAdminPath()+"/tb_goods_receipt_company/tbGoodsReceiptCompany/?repage";
	}
	/**
	 * 删除数据
	 * @param TbGoodsReceiptCompany
	 * @param Model
	 * @return String
	 */
	@RequiresPermissions("tb_goods_receipt_company:tbGoodsReceiptCompany:edit")
	@RequestMapping(value = "delete")
	public String delete(TbGoodsReceiptCompany tbGoodsReceiptCompany, RedirectAttributes redirectAttributes) {
		tbGoodsReceiptCompanyService.delete(tbGoodsReceiptCompany);
		addMessage(redirectAttributes, "删除收货公司成功");
		return "redirect:"+Global.getAdminPath()+"/tb_goods_receipt_company/tbGoodsReceiptCompany/?repage";
	}
	/**
	 * 获取数据
	 * @param HttpServletRequest
	 * @param HttpServletResponse
	 * @return Map<String,Object>
	 */	
	@RequestMapping("getgoodreceipt")
	@ResponseBody
	public Map<String,Object> getgoodreceipt(HttpServletRequest request, HttpServletResponse response){
		String id=request.getParameter("id");
		TbGoodsReceiptCompany entityaa = null;
		if (StringUtils.isNotBlank(id)){
			entityaa = tbGoodsReceiptCompanyService.get(id);
		}
		if (entityaa == null){
			entityaa = new TbGoodsReceiptCompany();
		}
		User createBy = entityaa.getCreateBy();
		User updateBy = entityaa.getUpdateBy();
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("goodsReceiptCompany", entityaa);
		map.put("updateBy", updateBy);
		map.put("createBy", createBy);
		return map;
	}
}